<?php
/**
 */
class GroupDetailsTable extends Doctrine_Table
{
	public function addDetailsToGroup($group_id,$user_id,$user_email)
	{
		$GroupDetails = new GroupDetails();
		$GroupDetails ->group_id = $group_id;
		$GroupDetails ->user_id = $user_id;
		$GroupDetails ->email_id = $user_email['email'];
		$GroupDetails ->user_name = $user_email['first_name'];
		$GroupDetails ->added_date = date('Y-m-d H:i:s');
		//echo '<pre>';print_r($GroupDetails);exit;
		$GroupDetails ->save();
		return $GroupDetails->id;
	}
	public function getGroupDetailsByid($group_id)
	{
		$query=new Doctrine_Query();
		    $query->select('g.*')
		       ->from('GroupDetails g')
			   ->where("group_id='".$group_id."'");
			  // ->andWhere("user_id='".$user_id."'");
			   //->andWhere("status='1'");
			    //echo $query;exit;
			   	$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
				//echo '<pre>';print_r($result);exit;
				return $result;
	}
	public function getGroupDetailsByUserId($group_id,$userId)
	{
		$query=new Doctrine_Query();
		    $query->select('g.id')
		       ->from('GroupDetails g')
			   ->where("group_id='".$group_id."'")
			   ->andWhere("user_id='".$userId."'");
			   //->andWhere("status='1'");
			    //echo $query;exit;
				//echo $query->getSqlQuery();exit;
			   	$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
				//echo '<pre>';print_r($result);exit;
				return $result;
	}
	public function getGroupDetailsByGroupId($group_id)
	{
		$query=new Doctrine_Query();
		    $query->select('g.*')
		       ->from('GroupDetails g')
			   ->where("group_id='".$group_id."'");
			   //->andWhere("status='1'");
			    //echo $query;exit;
			   	$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
				//echo '<pre>';print_r($result);exit;
				return $result;
	}
	public function getDetailsByid($id)
	{
		$query=new Doctrine_Query();
		    $query->select('g.*')
		       ->from('GroupDetails g')
			   ->where("id='".$id."'");
			   //->andWhere("status='1'");
			    //echo $query;exit;
			   	$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
				//echo '<pre>';print_r($result);exit;
				return $result[0];
	}
	public function updateGroupDetails($id,$name,$email)
	{
		$query = new Doctrine_Query();
		$query->update('GroupDetails')
			  ->set('user_name',"'$name'")
			  ->set('email_id',"'$email'")
			  ->where("id='".$id."'");
			  //echo $query;exit;
		return $query->execute();	  
	}
	public function removeRecord($user_id,$id)
	{
		$query = new Doctrine_Query();
		   $query->delete('GroupDetails g ')
			     ->Where('g.id='.$id);
				 //echo $query->getSqlQuery();exit;
           $result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
          return $result; 
	}
}